package com.avicit.zipkinkafkaesserver.config;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.bind.annotation.GetMapping;

import javax.ws.rs.GET;

/**
 * 定时任务相关配置
 */
@Slf4j
@Configuration
public class JobPropertiesConfig implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    @Getter
    private ConfigDB configDB;

    @Autowired
    @Getter
    private ConfigDBInterfaceCount configDBInterfaceCount;
    /**
     * 抓取记录开始时间
     */
    @Value("${job.startTime}")
    @Setter
    private String startTime;
    /**
     * 抓取记录结束时间
     */
    @Value("${job.endTime}")
    @Setter
    private String endTime;
    /**
     * 抓取条数
     */
    @Getter
    @Setter
    @Value("${job.limit}")
    private String limit;

    @Getter
    @Setter
    @Value("${job.fixedRate.interfaceCount}")
    private long fixedRateInterfaceCount;
    @Getter
    @Setter
    @Value("${job.fixedRate.interfaceAverageDuration}")
    private long fixedRateInterfaceAverageDuration;
    @Getter
    @Setter
    @Value("${job.fixedRate.interfaceDuration}")
    private long fixedRateInterfaceDuration;


    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        configDB.setEndTime(endTime);
        configDB.setStartTime(startTime);
        configDB.setStatus(true);//初始状态
        configDBInterfaceCount.setEndTime(endTime);
        configDBInterfaceCount.setStartTime(startTime);
        configDBInterfaceCount.setStatus(true);
        log.info("init startTime {}",startTime);
        log.info("init endTime {}",endTime);
    }
}
